package com.scrcu.core.batch.cotroller;

import com.alibaba.fastjson.JSONObject;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.common.util.RandomUtil;
import com.scrcu.core.batch.biz.BatchEventBiz;
import com.scrcu.core.batch.constant.BatchConstants;
import com.scrcu.core.batch.entity.BatchEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author: 刘超
 * @Date: 2023-05-15 8:56
 */
@RestController
@RequestMapping("/BatchEvent")
public class BatchEventBizController {
    @Autowired
    BatchEventBiz batchEventBiz;

    @GetMapping("/save")
    public String save() {
        BatchEvent batchEvent = new BatchEvent();
        batchEvent.setId("1ed43887abbb4d46bbfce3b513220ec3");
        batchEvent.setExeId("testExeId1");
        batchEvent.setStatus(BatchConstants.EXECUTION_STATUS_NEW);
        batchEvent.setAddr("127.0.0.1:8081");
        batchEvent.setContent("测试事件");
        batchEvent.setParams("测试参数");
        batchEvent.setStep("1");
        batchEventBiz.save(batchEvent);
        return "success";
    }

    @GetMapping("/get")
    public String get(@RequestParam("id") String id) {
        BatchEvent batchEvent = batchEventBiz.get(id);
        return JSONObject.toJSONString(batchEvent);
    }

    @GetMapping("/getList")
    public String getList(@RequestParam("pageNo") String pageNo){
        String exeId="testExeId";
        String endTime= Util.getStdmfDateTime();
        int pageSize = 10;
        PagedResult<BatchEvent> list = batchEventBiz.list(exeId, endTime, Integer.parseInt(pageNo), pageSize);
        return JSONObject.toJSONString(list);
    }
}
